/*
 * @Description: 路由
 * @Author: ldx
 * @Date: 2022-04-20 11:51:40
 * @LastEditors: ldx
 * @LastEditTime: 2022-09-28 21:33:00
 */
// import { Layout } from 'antd'
import { useRequest } from 'ahooks'
import React, { useEffect } from 'react'
import { Suspense } from 'react'
import {
  Route,
  Routes
  // useParams
} from 'react-router-dom'
import { useSetRecoilState } from 'recoil'

import { queryPublicKey } from '@/api/login'
import { RouteLoading } from '@/components'
import { commonState } from '@/recoil'

// import { getToken } from '@/utils'
// import { getStorage } from '@/utils'
// import styles from './index.less'
import routes from './routes'
// const { Footer } = Layout

const RouteList: React.FC = () => {
  // const navigate = useNavigate()
  // const params = useParams()
  // const location = useLocation()
  const setPublicKey = useSetRecoilState<any>(commonState.publicKey)
  // useEffect(() => {
  //   if (!userInfo) return
  //   // console.log('index', isLogin, 'istoken:', getStorage('token'))
  //   if (!userInfo.loginName && location.pathname != '/register') {
  //     navigate('/login')
  //   }
  // }, [userInfo])

  useRequest(queryPublicKey, {
    onSuccess: (res) => {
      setPublicKey(res.data)
    }
  })
  return (
    <Suspense fallback={<RouteLoading />}>
      <Routes>
        {(routes || []).map((route) => {
          const Component = route.component
          return (
            <Route path={route.path} element={<Component />} key={route.key} />
          )
        })}
      </Routes>
    </Suspense>
  )
}

export default RouteList
